package com.lmj.controller;

import com.lmj.service.ContentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.bind.DefaultValue;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.List;
import java.util.Map;

/**
 * 请求编写
 */

@RestController
@SuppressWarnings("All")
public class ContentController {
    @Autowired
    private ContentService contentService;

    /**
     * 根据关键字爬取数据
     *
     * @param keywords
     * @return
     * @throws IOException
     */
    @GetMapping("/parse/{keywords}")
    public Boolean parseJd(@PathVariable String keywords) throws IOException {
        return contentService.parseContent(keywords);
    }

    /**
     * 获取查询结果集
     * @param keywords
     * @param pageStart
     * @param pageSise
     * @return
     * @throws IOException
     */
    @GetMapping("/search/{keywords}/{pageStart}/{pageSise}")
    public List<Map<String, Object>> searchDataList(@PathVariable String keywords,
                                                    @PathVariable @DefaultValue("1") int pageStart,
                                                    @PathVariable @DefaultValue("10") int pageSise) throws IOException {
        return contentService.queryDataByKeyWords(keywords, pageStart, pageSise);
    }

    /**
     * 功能描述: <br>
     * 〈获取结果集高亮显示〉
     * @param keywords
     * @param pageStart
     * @param pageSise
     * @return: java.util.List<java.util.Map<java.lang.String,java.lang.Object>>
     * @author: limajun97@163.com
     * @date: 2020/12/30 下午6:03
     * @throws:
     */
    @GetMapping("/searchHigh/{keywords}/{pageStart}/{pageSise}")
    public List<Map<String, Object>> queryDataHighlightBuilder(@PathVariable String keywords,
                                                    @PathVariable @DefaultValue("1") int pageStart,
                                                    @PathVariable @DefaultValue("10") int pageSise) throws IOException {
        return contentService.queryDataHighlightBuilder(keywords, pageStart, pageSise);
    }
}
